package net.kangyee.eventmanager.commands;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import net.kangyee.eventmanager.EventManager;
import net.kangyee.eventmanager.util.MessageManager;

public class CmdGive extends EventManagerCommand {
	
	private EventManager plugin;
	
	public CmdGive(EventManager plugin){
		this.plugin = plugin;
	}

	public void onCommand(Player player, String[] args){
        if(args.length == 4){
        	if(!plugin.playerStateChecker(player, args[3])){
        		return;
        	}
        	Player targetPlayer = Bukkit.getPlayer(args[3]);
        	Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + args[3] + " " + args[1] + " " + args[2]);
        	MessageManager.sendNormalMessage(player, "成功给予玩家&6" + args[3] + "&f,&a" + args[2] + "&f个ID为&a" + args[1] + "&f的物品");
        	MessageManager.sendAdminMessage(targetPlayer, "你收到了&a" + args[2] + "&f个ID为&a" + args[1] + "&f的物品");   		
        	return;
            }
        if(args.length == 3){
        	for(Player localPlayer : plugin.regPlayers.keySet()){
        		Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give " + localPlayer.getName() + " " + args[1] + " " + args[2]);
        		MessageManager.sendAdminMessage(localPlayer, "你收到了&a" + args[2] + "&f个ID为&a" + args[1] + "&f的物品");   		
        	}
        	MessageManager.sendNormalMessage(player, "成功给予所有参加活动的玩家&f,&a" + args[2] + "&f个ID为&a" + args[1] + "&f的物品");
        	return;
        }
        return;
	}

	public String getCmdName(){
		return "give";
	}

	public String getArgs(){
		return "<物品id> <数量> [游戏名]";
	}
	
	public int getMaxArgs(){
		return 4;
	}

	public int getMinArgs(){
		return 3;
	}

	public String getPermission(){
		return "eventmanager.admin." + getCmdName();
	}

	public boolean getStateRequire(){
		return true;
	}
	
	public boolean getRegPCRequire() {
		return true;
	}
}
